package com.cqjtu.drive.controller;

import com.cqjtu.drive.pojo.Student;
import com.cqjtu.drive.response.Response;
import com.cqjtu.drive.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author zxl
 * @Date 2024/6/17 12:01
 */

@RestController
public class StudentController {
    @Autowired
    StudentService studentService;

    @PostMapping("/api/student/getallData")
    public Response<List<Student>> getallData() {
        return studentService.getAllStudents();
    }

    @PostMapping("/api/student/delete")
    public Response<String> deleteBysName(@RequestParam String sId) {
        return studentService.deleteStudent(sId);
    }

    @PostMapping("/api/student/getByName")
    public Response<List<Student>> getBysName(@RequestParam String sName) {
        return studentService.getBysName(sName);
    }

    @PostMapping("/api/student/update")
    public Response<String> update(@RequestBody Student student) {
        return studentService.updateStudent(student);
    }

    @PostMapping("/api/student/getByuserId")
    public Response<Student> getByuserId(@RequestParam String userId){
        return studentService.getStudentByuserId(userId);
    }
}
